home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / multitasking / priorities / priman / source / priman.h < prev    next >
C/C++ Source or Header  |  2000-03-05  |  13KB  |  368 lines

  1. /*
  2.  *        Task Priority Manager
  3.  *        Copyright 1993, 1994 Barry McConnell
  4.  *        bmccnnll@tcd.ie
  5.  *
  6.  *        PriMan's header file. Contains constant definitions, function protypes,
  7.  *        and global variables.
  8.  *
  9.  *        Set tab stops to 4 when editing this file.
  10.  *
  11.  *        Every source file #includes this, but we only want one of them to
  12.  *        actually define the global variables (and the rest to just declare
  13.  *        them). So I use Eddy Carroll's trick of prefixing all definitions by a
  14.  *        keyword that gets set to nothing by one file, and "extern" by all the
  15.  *        rest. Hence, one file should #define MAIN, and it will be that file
  16.  *        which actually defines the variables.
  17.  */
  18. #ifdef MAIN
  19. #define GLOBAL
  20. #else
  21. #define GLOBAL extern
  22. #endif
  23.  
  24. #define __USE_SYSBASE    /* speeds things up on '020 processors (or greater), as ExecBase is cached */
  25. #include "system.h"        /* the system header files */
  26.  
  27. /*
  28.  *        The current version number and date go here, and are referenced in
  29.  *        several places from the other files. This makes it easy to do a global
  30.  *        update of the version information.
  31.  */
  32. #define VERSION            "2.0"
  33. #define DATE            "13.11.94"
  34.  
  35. /*
  36.  *        Here is another one of Eddy's ideas - a cute macro to walk through a
  37.  *        linked list. This does all the casting itself!
  38.  */
  39. #define FORLIST(list,p)    for ((p) = (void *)(list) -> lh_Head;                \
  40.                             ((struct Node *)(p)) -> ln_Succ;                \
  41.                             (p) = (void *)((struct Node *)(p)) -> ln_Succ)
  42.  
  43. /*
  44.  *        This saves us bringing in printf() for simple messages.
  45.  */
  46. #define Print(s)        Write(Output(), s, strlen(s))
  47.  
  48. /*
  49.  *        For the Freeze Task option, we need two extra Exec task states. The
  50.  *        first one is used when the task was Wait()ing on a signal, and the
  51.  *        second when it was ready to run when frozen.
  52.  */
  53. #define FROZEN            (1<<6)
  54. #define FROZENREADY        (1<<5)
  55.  
  56. /*
  57.  *        These are defines for the status of the Window Type and Open On cycle
  58.  *        gadgets.
  59.  */
  60. #define SMARTWINDOW        0
  61. #define SIMPLEWINDOW    1
  62. #define DEFAULTSCREEN    0
  63. #define FRONTSCREEN        1
  64.  
  65. /*
  66.  *        Both windows get these IDCMP flags (although technically the Settings
  67.  *        window doesn't need many of them).
  68.  */
  69. #define WINDOWIDCMP     IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW | IDCMP_NEWSIZE |    \
  70.                         IDCMP_SIZEVERIFY | IDCMP_MENUPICK | IDCMP_VANILLAKEY |        \
  71.                         IDCMP_RAWKEY | BUTTONIDCMP | LISTVIEWIDCMP
  72.  
  73. /*
  74.  *        Here are some general constants used in the code, some of which are a
  75.  *        little arbitrary...
  76.  */
  77. #define MaxTasks        256        /* hardcoded maximum number of task we'll process                            */
  78. #define MaxHotkey        20        /* maximum number of characters in a Commodities hotkey                        */
  79. #define MaxToolTypes    30        /* maximum allowable number of ToolTypes in PriMan's .info file                */
  80. #define MaxStdTools        19         /* number of ToolTypes we reserve for ourselves                                */
  81. #define MaxToolName        10        /* longest ToolType name ("LISTFONT=" plus NULL at end)                        */
  82. #define ScrollBarWidth    16        /* width of a ListView scrollbar                                            */
  83. #define ListEarlyClip    6        /* number of extra horizontal pixels ListView needs under 2.x                */
  84. #define CloseBoxWidth    19        /* width of a close gadget (so we can neatly indent the Settings window)    */
  85. #define    CycleWidth        24        /* width of a cycle gadget's imagery                                        */
  86. #define PressDelay        5        /* duration a button gets highlighted for if its keyboard shortcut is used    */
  87. #define BreakDelay        25        /* amount of time to wait after sending a Break signal to a task            */
  88.  
  89. /*
  90.  *        For the non-printable keyboard shortcuts, their values are included
  91.  *        here. The first three are VANILLAKEY, with the last being RAWKEY.
  92.  */
  93. #define TAB                9
  94. #define RETURN            13
  95. #define ESCAPE            27
  96. #define HELP            95
  97.  
  98. /*
  99.  *        Every gadget must have a unique identifier, listed here.
  100.  */
  101. #define LISTGAD         1
  102. #define SLIDERGAD        2
  103. #define BREAKGAD        3
  104. #define KILLGAD         4
  105. #define SETTINGSGAD     6
  106. #define GFONTGAD        7
  107. #define LFONTGAD        8
  108. #define GBOXGAD         9
  109. #define LBOXGAD         10
  110. #define CONFIRMGAD        11
  111. #define ICONIFYGAD        12
  112. #define SAVEGAD         13
  113. #define USEGAD            14
  114. #define CANCELGAD        15
  115. #define COMGAD            16
  116. #define POPUPGAD        17
  117. #define HOTKEYGAD        18
  118. #define PRIORITYGAD        19
  119. #define TOOLPRIGAD        20
  120. #define PAGEGAD            21
  121. #define REFRESHGAD        22
  122. #define OPENGAD            23
  123.  
  124. /*
  125.  *        These are the possible errors PriMan can encounter.
  126.  */
  127. #define LOCK_ERROR        1
  128. #define VISINFO_ERROR    2
  129. #define FONT_ERROR        3
  130. #define GADGET_ERROR    4
  131. #define MAIN_ERROR        5
  132. #define TASK_ERROR        6
  133. #define SETTINGS_ERROR    7
  134. #define CX_ERROR        8
  135. #define MENU_ERROR        9
  136.  
  137. /*
  138.  *        This isn't really an error; it just allows PriMan to fall out of the
  139.  *        main loop, and then exit.
  140.  */
  141. #define ALL_OKAY        100
  142.  
  143. /*
  144.  *        Here are the defines for the various menu items. They are dependent on
  145.  *        the position each item appears in the NewMenu structure. The prefixes
  146.  *        mean the following:
  147.  *
  148.  *            M = menu title
  149.  *            I = menu item
  150.  *            S = sub menu item (not used)
  151.  */
  152. #define M_PROJECT    0
  153.  
  154. #define I_SETTINGS    0
  155. #define I_ABOUT        2
  156. #define I_HELP        3
  157. #define I_HIDE        5
  158. #define I_QUIT        6
  159.  
  160. #define M_TASK        1
  161.  
  162. #define I_UPDATE    0
  163. #define I_KILL        2
  164. #define I_SIGNAL    4
  165. #define I_PRIORITY    5
  166. #define I_FROZEN    7
  167. #define I_WIDE        9
  168.  
  169. /*
  170.  *        All the functions get declared here. The first bunch are
  171.  *        from Main.c, Window.c and Event.c:
  172.  */
  173. void main(int, char **);
  174. void HandleToolTypes(char **, BOOL *);
  175. void OpenMainWindow(void);
  176. void OpenSettingsWindow(void);
  177. void CreateList(struct Remember **);
  178. void CreateString(struct Task *, char *);
  179. void HandleMainWindow(ULONG, WORD, WORD, WORD, UWORD, UWORD, struct Gadget *);
  180. void HandleSettingsWindow(ULONG, WORD, WORD, WORD, UWORD, struct Gadget *);
  181.  
  182. /*
  183.  *        The rest are from Util.c (alphabetically sorted):
  184.  */
  185. void BusyPointer(void);
  186. void CloseMainWindow(void);
  187. void CloseSettingsWindow(void);
  188. void CloseWindowSafely(struct Window *);
  189. int  Compare(char *, char *);
  190. int  CompareTasks(char *, char *);
  191. void DrawSettingsBox(void);
  192. void FontString(struct TextAttr *, char *);
  193. BOOL Frozen(struct Task *);
  194. void GetListTop(void);
  195. void GetPos(void);
  196. void Help(void);
  197. void Hide(void);
  198. void Iconify(void);
  199. struct Screen *LockOurScreen(BOOL);
  200. void MenuEllipsis(struct Menu *, BOOL);
  201. void NewPage(WORD);
  202. void NormalPointer(void);
  203. void OffTask(void);
  204. void OnTask(void);
  205. void PressGadget(struct Window *, struct Gadget *);
  206. void Range(WORD *, WORD, WORD);
  207. BOOL RequestFont(struct FontRequester **, struct FontRequester *, char *, WORD *, struct Gadget *, char *, char *, ULONG);
  208. void SetupCommodity(void);
  209. void Show(void);
  210. LONG SimpleRequest(struct EasyStruct *, APTR);
  211. int  __regargs sprintf(char *, char *, ...);
  212. WORD Step(WORD, WORD, UWORD);
  213. BOOL ValidTask(struct Task *);
  214. void WideSlider(BOOL);
  215. void WipePort(struct MsgPort *);
  216.  
  217. /*
  218.  *        Here is a standard Node type with extra space to store a pointer to the
  219.  *        original task structure, so we can find it again.
  220.  */
  221. struct ListType
  222.     {
  223.     struct Node    mainNode;
  224.     struct Task    *mainTask;
  225.     };
  226.  
  227. /*
  228.  *        Finally, all the global variables go here. A lot of them rely on the
  229.  *        fact that they get initialised to zero at runtime.
  230.  */
  231. GLOBAL int        taskCount,                    /* number of tasks in ListView                        */
  232.                 pos,                        /* currently-selected task (or -1 if none)            */
  233.                 taskLength,                    /* maximum length of an entry in ListView            */
  234.                 error;                        /* something bad happened - abort ASAP                */
  235.  
  236. GLOBAL ULONG    guideSignal;                /* if set, we need to check for AmigaGuide messages    */
  237.  
  238. GLOBAL LONG        top;                        /* ordinal number of top entry    */
  239.  
  240. GLOBAL UWORD    osver;                        /* Kickstart version                                */
  241.  
  242. GLOBAL WORD        winLeft, winTop,            /* these are the main window's dimensions            */
  243.                 winWidth, winHeight,
  244.                 minWidth, minHeight,        /* minimum space gadgetry will fit into                */
  245.                 iconLeft, iconTop,            /* position of AppIcon                                */
  246.                 windowTop,                    /* height of window's title bar                        */
  247.                 height,                        /* height of default screen (Gadget) font            */
  248.                 sysHeight, sysWidth,        /* height and width of system default (List) font    */
  249.                 setGadStart, setGadHeight,    /* top edge and height of Settings gadget page        */
  250.                 page;                        /* current page of Settings gadgets (or -1 if none)    */
  251.  
  252. GLOBAL BOOL        newPropFont,                /* a new Gadget font was chosen                        */
  253.                 newMonoFont;                /* a new List font was chosen                        */
  254.  
  255. GLOBAL char        myName[40];                    /* pathname used when manipulating the .info file    */
  256.  
  257. GLOBAL void        *visInfo;                    /* VisualInfo structure for GadTools                */
  258.  
  259. GLOBAL CxObj    *broker,                    /* parts making up the Commodity structure            */
  260.                 *filter,
  261.                 *sender,
  262.                 *translate;
  263.  
  264.                 /*
  265.                  *        These are the strings placed in the Gadget and List font
  266.                  *        boxes. (Sizewise they are no longer than those in the
  267.                  *        font structures, since the ".font" part is stripped off,
  268.                  *        and replaced with the font size.)
  269.                  */
  270. GLOBAL char        propString[MAXFONTNAME],
  271.                 monoString[MAXFONTNAME];
  272.  
  273.                 /*
  274.                  *        The next few variables are the settings in operation at
  275.                  *        the moment. (The font names are here, but their sizes
  276.                  *        are stored in the TextAttr structures below.)
  277.                  */
  278. GLOBAL WORD        refresh,                    /* Window Type                                        */
  279.                 open,                        /* Open On                                            */
  280.                 commodity,                    /* Install as a Commodity                            */
  281.                 popup,                        /* Popup When Launched                                */
  282.                 confirm,                    /* Confirm Actions                                    */
  283.                 iconify;                    /* Iconify When Closed                                */
  284. GLOBAL char        propName[MAXFONTNAME],        /* name of Gadget Font                                */
  285.                 monoName[MAXFONTNAME],        /* name of List Font                                */
  286.                 hotkey[MaxHotkey + 1];        /* Commodity hotkey                                    */
  287. GLOBAL BYTE        priority;                    /* Commodity priority                                */
  288.  
  289.                 /*
  290.                  *        These variables are temporary copies of the settings
  291.                  *        above which the user plays around with from the Settings
  292.                  *        window. We don't need temporary copies of the hotkey or
  293.                  *        priority values, since the string and integer gadgets
  294.                  *        serve that purpose. But we do need copies of the two
  295.                  *        font structures - or more precisely, the names and sizes
  296.                  *        embedded within them. We can't rely on the ASL font
  297.                  *        requester to store these, since the user might pick a
  298.                  *        different font and then click Cancel!
  299.                  */
  300. GLOBAL WORD        tempRefresh,
  301.                 tempOpen,
  302.                 tempCommodity,
  303.                 tempPopup,
  304.                 tempConfirm,
  305.                 tempIconify,
  306.                 tempPropSize,
  307.                 tempMonoSize;
  308. GLOBAL char        tempPropName[MAXFONTNAME],
  309.                 tempMonoName[MAXFONTNAME];
  310.  
  311. GLOBAL AMIGAGUIDECONTEXT    guideHandle;    /* reference to AmigaGuide file                        */
  312.  
  313. GLOBAL struct NewAmigaGuide    myGuide;        /* AmigaGuide structure used when opening file        */
  314. GLOBAL struct Library        *AmigaGuideBase;    /* AmigaGuide library base for online help        */
  315. GLOBAL struct Screen        *myScreen;        /* public screen PriMan is open on                    */
  316. GLOBAL struct Window        *mainWindow,    /* PriMan's main window                                */
  317.                             *setWindow;        /* PriMan's Settings window                            */
  318. GLOBAL struct Menu            *menuStrip;        /* main window's menu strip                            */
  319. GLOBAL struct TextAttr        propTA,            /* structure used for opening the Gadget Font        */
  320.                             monoTA;            /* structure used for opening the List Font            */
  321. GLOBAL struct TextFont        *propFont,        /* pointer to opened Gadget Font                    */
  322.                             *monoFont;        /* pointer to opened List Font                        */
  323. GLOBAL struct List             taskList;        /* contents of ListView                                */
  324. GLOBAL struct MsgPort        *winPort,        /* window message port                                */
  325.                             *cxPort,        /* Commodities message port                            */
  326.                             *appPort;        /* AppIcon message port                                */
  327. GLOBAL struct DiskObject    *myIcon,        /* PriMan's .info file                                */
  328.                             *wbIcon;        /* AppIcon template (essentially a copy of myIcon)    */
  329. GLOBAL struct AppIcon        *appIcon;        /* AppIcon structure                                */
  330. GLOBAL struct Image            blank;            /* for clearing gadget imagery                        */
  331. GLOBAL struct Remember        *memoryKey;        /* memory occupied by task list                        */
  332. GLOBAL struct Node            *current;        /* entry in ListView currently selected                */
  333. GLOBAL struct Task            *currentTask;    /* structure of task currently selected                */
  334. GLOBAL struct FontRequester *propFontReq,    /* ASL Gadget font requester                        */
  335.                             *monoFontReq;    /* ASL List font requester                            */
  336. GLOBAL struct Gadget        *mainGads,        /* gadgets in main window                            */
  337.                             *setGads[4],    /* gadgets in Settings window                        */
  338.                             *listGad,        /* individual gadget structures                        */
  339.                             *sliderGad,
  340.                             *breakGad,
  341.                             *killGad,
  342.                             *setGad,
  343.                             *pageGad,
  344.                             *saveGad,
  345.                             *useGad,
  346.                             *cancelGad,
  347.                             *propFontGad,
  348.                             *propFontButGad,
  349.                             *monoFontGad,
  350.                             *monoFontButGad,
  351.                             *refreshGad,
  352.                             *confirmGad,
  353.                             *iconifyGad,
  354.                             *openGad,
  355.                             *toolpriGad,
  356.                             *comGad,
  357.                             *popupGad,
  358.                             *hotkeyGad,
  359.                             *priorityGad;
  360.  
  361. /*
  362.  *        The last couple of variables are actually defined in other source files
  363.  *        (because it's easier to initialise them once there), but used by several
  364.  *        different files, and hence are always extern here.
  365.  */
  366. extern struct ExecBase        *SysBase;        /* ExecBase structure, from the includes            */
  367. extern struct NewBroker        newBroker;        /* Commodity broker structure, from main.c            */
  368.